package com.sporadic.backstage.controller;

import com.sporadic.backstage.dto.StoreProfileDTO;
import com.sporadic.backstage.entity.Order;
import com.sporadic.backstage.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
@CrossOrigin(origins = {"http://localhost:8080"}, methods = {RequestMethod.GET, RequestMethod.POST}, allowCredentials = "true")
@Controller
public class OrderController {

    @Autowired
    private OrderService orderService;


    /**
     * 查询店铺概况
     * @param merchantId 商家ID
     * @param date  0 今天 1 本周 2本月
     * @return 返回 综合收入、优惠金额、订单平均消费、成交笔数、退款金额、会员总数
     */
    @ResponseBody
    @RequestMapping("/findStoreProfile")
    public StoreProfileDTO findStoreProfile(Integer merchantId, Integer date){
        return orderService.findStoreProfile(merchantId,date);
    }


    /**
     * 查询销售分析
     * @param merchantId 商家ID
     * @param date  0 今天 1 本周 2本月
     * @return 返回销售情况
     */
    @ResponseBody
    @RequestMapping("/findSalesAnalysis")
    public List<String> findSalesAnalysis(Integer merchantId,Integer date){
        System.out.println(merchantId+"         "+date);
        return orderService.findSalesAnalysis(merchantId, date);
    }





    /**
     * 查询商家今年会员消费排行前3
     * @param merchantId 商家编号
     * @return
     */
    @ResponseBody
    @RequestMapping("/selTop3TotalCountUser")
    public List<Order>selTop3TotalCountUser(Integer merchantId){
        return orderService.selTop3TotalCountUser(merchantId);
    }

}
